import pao = require('../pao/public');
import paoClient = require('../pao/client/client');

let moduleName = "pao.test";

/**
 * 数据服务测试视图
 */
@pao.addon("数据服务测试视图", "数据服务测试视图", moduleName)
@paoClient.template('views/dbTest.html')
export class dbTestView extends paoClient.baseView {

    $asyncDBTest?:JQuery = undefined;

    $asyncProxyDBTest?:JQuery = undefined;

    $result?:JQuery = undefined;

    $resultTitle?:JQuery = undefined;

    onAfterBind?(){
        this.$asyncDBTest.click(()=>{
            paoClient.asyncJsonCall("http://localhost:3000/remoteCall",
                "example",
                "query",
                ["cmd_dj_nsrxx",{}],
                (result)=>{
                    console.log(pao.addonSerialize(result));
                    this.$resultTitle.text(`没有Where条件结果集`)
                    this.$result.text(pao.addonSerialize(result));
                },
                (error)=>{
                    this.$result.text(error.message);
                });
        });

        this.$asyncProxyDBTest.click(()=>{
            let factoy = <pao.baseDataFetcher>new paoClient.remoteFactory(pao.baseDataFetcher,"remoteCall","example").getValue();
            try {
                let result = factoy.query("cmd_dj_nsrxx",{});//
                this.$resultTitle.text(`有Where条件结果集`)
                this.$result.text(pao.addonSerialize(result));
            }catch(error){
                this.$result.text(error);
            }
        });
    }
}